package com.lzx.dormsys.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lzx.dormsys.bean.DoorBean;
import com.lzx.dormsys.bean.RoomtypeBean;
import com.lzx.dormsys.bean.SysDeptBean;
import com.lzx.dormsys.core.AjaxResult;
import com.lzx.dormsys.core.controller.BaseController;
import com.lzx.dormsys.service.IDoorBeanService;
import com.lzx.dormsys.service.IRoomtypeBeanService;
import com.lzx.dormsys.service.ISysDeptBeanService;
import com.lzx.dormsys.service.impl.RoomtypeBeanServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lzx.dormsys.bean.AreaBean;
import com.lzx.dormsys.service.IAreaBeanService;

/**
 * areaController
 *
 * @author lzx
 * @date 2021-09-10
 */
@RestController
@RequestMapping("/areaAction")
public class AreaBeanController extends BaseController {
    @Autowired
    private IAreaBeanService areaBeanService;

    @Autowired
    private ISysDeptBeanService deptBeanService;

    @Autowired
    private IRoomtypeBeanService roomtypeBeanService;

    /**
     * 查询area详细列表
     */
    @GetMapping("/listplus")
    public AjaxResult listplus(AreaBean areaBean) {
        List<AreaBean> areaBeans = areaBeanService.selectAreaBeanList(areaBean);
        List<SysDeptBean> sysDeptBeans = deptBeanService.selectSysDeptBeanList(null);
        List<RoomtypeBean> roomtypeBeans = roomtypeBeanService.selectRoomtypeBeanList(null);
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("areaList",areaBeans);
        resultMap.put("deptList",sysDeptBeans);
        resultMap.put("roomtypeList",roomtypeBeans);

        return AjaxResult.success(resultMap);
    }

    /**
     * 查询area列表
     */
    @GetMapping("/list")
    public AjaxResult list(AreaBean areaBean) {
        List<AreaBean> list = areaBeanService.selectAreaBeanList(areaBean);
        return AjaxResult.success(list);
    }

    /**
     * 获取area详细信息
     */
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId) {
        return AjaxResult.success(areaBeanService.selectAreaBeanById(areaId));
    }

    /**
     * 新增area
     */
    @PostMapping
    public AjaxResult add(@RequestBody AreaBean areaBean) {
        return toAjax(areaBeanService.insertAreaBean(areaBean));
    }

    /**
     * 修改area
     */
    @PutMapping
    public AjaxResult edit(@RequestBody AreaBean areaBean) {
        return toAjax(areaBeanService.updateAreaBean(areaBean));
    }

    /**
     * 删除area
     */
    @DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds) {
        return toAjax(areaBeanService.deleteAreaBeanByIds(areaIds));
    }
}
